/*! \file 
    \brief Holds declarations for the synchronization sub-system. */

#ifndef _SYNC_H_
#define _SYNC_H_

/* Put any declarations you need to add to implement assignment 5 here. */

#define MAX_NUMBER_OF_SEMAPHORES MAX_NUMBER_OF_THREADS
#define MAX_NUMBER_OF_BLOCKED_SEMAPHORE_THREADS 32

struct queue{
    int blocked_threads[MAX_NUMBER_OF_BLOCKED_SEMAPHORE_THREADS];
    int head;
    int tail;
};

struct semaphore{
    int count;
    int owner;
    struct queue blocked;
};

// The semaphore_table is NOT indexed with the thread index.
extern struct semaphore semaphore_table[MAX_NUMBER_OF_SEMAPHORES];

void semaphore_reset(long semahore_handle);
int semaphore_enqueue(int thread_index, long semaphore_handle);
int semaphore_dequeue(long semaphore_handle);

#endif